package com.zhl.media.commonsdk.utils;

import android.net.Uri;
import android.os.Environment;

import org.devio.takephoto.app.TakePhoto;
import org.devio.takephoto.compress.CompressConfig;
import org.devio.takephoto.model.TakePhotoOptions;

import java.io.File;

public class CameraUtil {

    public static void takePhotoCompress(TakePhoto takePhoto){
        File file = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/MEDIA_PIC", System.currentTimeMillis() + ".jpg");
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        Uri imageUri = Uri.fromFile(file);
        CompressConfig config = new CompressConfig.Builder().setMaxSize(50 * 1024).setMaxPixel(1200).create();
        takePhoto.onEnableCompress(config,true);
        TakePhotoOptions.Builder builder = new TakePhotoOptions.Builder();
        builder.setCorrectImage(true);
        takePhoto.setTakePhotoOptions(builder.create());
        takePhoto.onPickFromCapture(imageUri);
    }

}
